package com.gitee.wsl.compose.ui.calendar.view

import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight

import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.gitee.wsl.time.calendar.bean.CalendarMonth
import com.gitee.wsl.time.local.KlockLocale
import kotlinx.datetime.DayOfWeek
import kotlinx.datetime.Month
import kotlin.time.ExperimentalTime

typealias MonthHeaderFooterSlate =  @Composable ColumnScope.(CalendarMonth, DayOfWeek,KlockLocale) -> Unit

object MonthHeaderFooter

@OptIn(ExperimentalTime::class)
val MonthHeaderFooter.defaultHeader :MonthHeaderFooterSlate get() =  { calendarMonth: CalendarMonth,firstDayOfWeek:DayOfWeek,local->
	MonthHeader(month = calendarMonth.yearMonth.month, year = calendarMonth.yearMonth.year.value,  local = local)
}

@OptIn(ExperimentalTime::class)
val MonthHeaderFooter.defaultWeekHeader :MonthHeaderFooterSlate get() =  { calendarMonth: CalendarMonth,firstDayOfWeek:DayOfWeek,local->
	WeekHeaderFooter.defaultHeader(this,calendarMonth.weekDays.first(),firstDayOfWeek,local)
}

/**
 * Default Month header used to display month as text.
 */
@Composable
fun MonthHeader(
	month: Month,
	year: Int,
	local: KlockLocale
) {
	Text(
		"${local.monthsShort.getOrNull(month.ordinal)} $year",
		modifier = Modifier.fillMaxWidth().padding(bottom = 20.dp, top = 0.dp),
		textAlign = TextAlign.Center,
		fontWeight = FontWeight.ExtraLight,
		fontSize = 16.sp,
	)
}
